package com.tucy.logistics.modules.goods.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tucy.logistics.common.dto.goods.GoodsTypeTransportDto;
import com.tucy.logistics.common.entity.goods.GoodsTypeTransport;
import com.tucy.logistics.modules.goods.service.GoodsTypeTransportService;
import com.tucy.logistics.modules.goods.mapper.GoodsTypeTransportMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author tucy123
* @description 针对表【goods_type_transport(货物类型运输表)】的数据库操作Service实现
* @createDate 2023-10-12 15:26:34
*/
@Service
public class GoodsTypeTransportServiceImpl extends ServiceImpl<GoodsTypeTransportMapper, GoodsTypeTransport> implements GoodsTypeTransportService{

    @Autowired
    GoodsTypeTransportMapper goodsTypeTransportMapper;

    /**
     * 货品运输查询
     * @param goodsTypeTransportDto
     * @return
     */
    @Override
    public Page<GoodsTypeTransport> queryAll(GoodsTypeTransportDto goodsTypeTransportDto) {
        Page<GoodsTypeTransport> page = new Page<>(goodsTypeTransportDto.getPageNum(),goodsTypeTransportDto.getPageSize());

        QueryWrapper<GoodsTypeTransport> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .like(ObjectUtil.isNotEmpty(goodsTypeTransportDto.getName()),GoodsTypeTransport::getName,goodsTypeTransportDto.getName())
                .like(ObjectUtil.isNotEmpty(goodsTypeTransportDto.getVehicleTypeName()),GoodsTypeTransport::getVehicleTypeName,goodsTypeTransportDto.getVehicleTypeName())
                .eq(ObjectUtil.isNotEmpty(goodsTypeTransportDto.getVehicleTypeId()),GoodsTypeTransport::getVehicleTypeId,goodsTypeTransportDto.getVehicleTypeId());

        return goodsTypeTransportMapper.selectPage(page,wrapper);
    }

    /**
     * 增改货品运输
     * @param goodsTypeTransport
     * @return
     */
    @Override
    public Boolean saveUpdateGoods(GoodsTypeTransport goodsTypeTransport) {
        return this.saveOrUpdate(goodsTypeTransport);
    }

    /**
     * 删除货品运输
     * @param id
     * @return
     */
    @Override
    public Boolean deleteGoodsTransport(String id) {
        int i = goodsTypeTransportMapper.deleteById(id);
        return i == 1;
    }

    /**
     * 货品运输详情
     * @param id
     * @return
     */
    @Override
    public GoodsTypeTransport detailsGoodsTransport(String id) {
        return goodsTypeTransportMapper.selectById(id);
    }
}




